#!/bin/sh
#
#
# see: dh_installdeb(1)

set -e

. /etc/default/openmediavault
. /usr/share/openmediavault/scripts/helper-functions


case "$1" in
    configure)

	# Enable required apache modules
	a2enmod authnz_external dav_svn dav_fs

	# Check for XML config
    if ! omv_config_exists "//services/git"; then
		omv_config_add_element "//services" "git" ""
		omv_config_add_element "//services/git" "enable" "0"
		omv_config_add_element "//services/git" "mntentref" ""
		omv_config_add_element "//services/git" "realm" "Git Repositories on OMV"
		omv_config_add_element "//services/git" "repository-root" ""
		omv_config_add_element "//services/git" "repos" ""
		omv_config_add_element "//services/git" "gitweb-enable" "0"
		omv_config_add_element "//services/git" "gitweb-anon" "0"
	fi

	# Fix permissions
	omv_install_fixperms
	
	chown -R openmediavault:openmediavault /var/www/gitweb
	
	# Clean up old installation?
	if [ -f /etc/apache2/conf.d/omv-git ]; then
		/bin/rm -f /etc/apache2/conf.d/omv-git	
	fi
	
	omv-mkconf git
	
	monit restart apache2

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
